﻿@using Orchard.Utility.Extensions;
@using Contrib.Chapters.Models;

@{
    Style.Include("chapters.css");
    int level=-1;
}

<div class="chapters-toc">
    <ul>
		<li @if (Request.Path.EndsWith(Model.Book.Path)) {<text>class="current"</text>}>
			<h1>@Html.ItemDisplayLink((string)Model.Book.Name, (Orchard.ContentManagement.ContentItem)Model.Book.ContentItem)</h1>
			@foreach (Contrib.Chapters.Models.ChapterPart chapter in Model.Chapters) {
				if(chapter.Level > level) {
					level++;
					@:<ul class="chapters">
				}
				else if(chapter.Level < level) {
					level--;
					@:</ul>
				}
				else {
					@:</li>
				}

				@:<li @if (Request.Path.EndsWith(chapter.Path)) {<text>class="current"</text>}>
					@Html.ItemDisplayLink((string)chapter.Title, chapter.ContentItem)
			}
        
				</li>
			@for (int i = 0; i < level; i++) {
			@:</ul>
			}
		</li>
	</ul>
</div>